<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Table</title>
	<link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" href="/static/css/global.css" media="all">
	<link rel="stylesheet" href="/static/plugins/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="/static/css/table.css"/>
</head>

<body>
<div class="admin-main" templateLoad onFinishCallback="onFinishCallback">
	<blockquote class="layui-elem-quote">
		<a href="./list.html" class="layui-btn layui-btn-small"> <i class="layui-icon">&#xe608;</i>用户列表 </a>
	</blockquote>

	<form class="layui-form" action="/admin/user/gant_permission">
		<input type="hidden" name="id" bindAttr="id">

		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="name" bindAttr="name" class="layui-input" disabled="disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">授权</label>
			<div class="layui-input-block">
				<ul id="authlist"></ul>

				<!-- 权限模板 -->
				<script type="text/html" id="authlist_tpl">
					{{# layui.each(d, function(index, item){ }}
					<li><input type="checkbox" name="gantEnvs" lay-skin="primary" title="{{ item.text }}" value="{{ item.value }}"></li>
					{{# }); }}
				</script>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="button" class="layui-btn J_ajaxSubmit" onSuccessJumpurl="./list.html" value="保存"/>
				<input type="reset" class="layui-btn layui-btn-primary" value="重置"/>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/common.js?v20180106?a=91"></script>
<script type="text/javascript">
	function onFinishCallback(data) {
		var $ = layui.jquery;
		var $cont = $('#authlist');
		$.getJSON('/admin/user/auth_options', function (res) {
			var tpl = $('#authlist_tpl').html();
			layui.laytpl(tpl).render(res.data, function (html) {
				$cont.html(html);
			});

			$cont.find(':checkbox').each(function () {
				var $this = $(this);
				if (data.gantEnvs.indexOf($this.attr('value')) >= 0) {
					$this.attr('checked', true);
				}
			});
			layui.form().render();
		});
	}
</script>
</body>
</html>